package com.deep.spring.v31;

import org.springframework.beans.BeanUtils;

/**
 * https://blog.csdn.net/iteye_19045/article/details/119299015
 *
 * @author sw
 * @create 2022-12-16 17:10
 */
public class MyBeanUtilsTest {

    public static void main(String[] args) {
        User user1 = new User(1, "张三", "男", 18);
        User user2 = new User();
        User user3 = new User();

        //通过Spring的 BeanUtils 工具类拷贝对象，并且忽略“sex"和”age"两个字段
        BeanUtils.copyProperties(user1, user2, "sex", "age");
        System.out.println(user2);
        //通过自定义的 MyBeanUtils 工具类拷贝对象，并且忽略“sex"和”age"两个字段
        MyBeanUtils.copyProperties(user1, user3, User::getSex, User::getAge);
        System.out.println(user3);

//        System.out.println("user1 = " + user1);
//        System.out.println("user2 = " + user2);
        System.out.println("user3 = " + user3);

    }
}
